{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>编辑</h5>
                </div>
                <div class="ibox-content layui-form">
                    <div class="layui-row layui-col-space10 layui-form-item">
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">用户头像：</label>
                            <input type="hidden" name="user_image" id="lay-img" lay-verify="image" value="{$info.user_image}">
                            <div class="layui-input-block">
                                <div id="lay-upload">上传图片</div>
                                <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                                    预览图：
                                    <div class="layui-upload-list" id="lay-list">
                                        <img class="layui-append-img" src="{$info.user_image}" onerror="this.src='/static/admin/images/no_img.jpg'">
                                    </div>
                                </blockquote>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">昵称</label>
                            <div class="layui-input-block">
                                <input type="text" lay-verify="required" name="user_username" class="layui-input" value="{$info.user_username}">
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">手机号</label>
                            <div class="layui-input-block">
                                <input type="text" lay-verify="required" class="layui-input" value="{$info.user_phone}" name="user_phone">
                            </div>
                        </div>
                        {if $disp == 2}
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">姓名</label>
                            <div class="layui-input-block">
                                <input lay-verify="required" type="text" class="layui-input" value="{$info.uson_username}" name="uson_username">
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">身份证(为空则解绑)</label>
                            <div class="layui-input-block">
                                <input type="text" class="layui-input" value="{$info.uson_idcard}" name="uson_idcard">
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">入学年份</label>
                            <div class="layui-input-block">
                                <input lay-verify="required" type="text" class="layui-input" value="{$info.uson_year}" name="uson_year">
                            </div>
                        </div>
                        <!---->
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">学校：</label>
                            <div class="layui-input-block">
                                <select id="l_piano" lay-verify="required" lay-filter="role" name="p_piano" lay-search>
                                    <option value="">请选择</option>
                                    {foreach name="schools" item="v"}
                                    <option value="{$v.school_id}" {if $v.school_id==$info.uson_school}selected{/if}>{$v.school_name}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">年级：</label>
                            <div class="layui-input-block">
                                <select id="l_student" lay-verify="required" name="p_student" lay-search>
                                    <option value="">请选择年级</option>
                                    {foreach name="grades" item="v"}
                                    <option value="{$v.grade_id}" {if $v.grade_id==$info.uson_grade_id}selected{/if}>{$v.grade_name}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>
                        <!---->
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">班级</label>
                            <div class="layui-input-block">
                                <input type="text" class="layui-input" value="{$info.uson_class}" name="uson_class">
                            </div>
                        </div>
                        {/if}
                        <input type="hidden" value="{$user_id}" name="user_id">
                        <input type="hidden" value="{$uson_id}" name="uson_id">
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit="" lay-filter="component-form-element">保存
                                </button>
                                <button class="layui-btn layui-btn-primary" onclick="wk.layer_close('close')">关闭</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
</body>
</html>
<script>
    wk.uploadImg({size:5,type:'png,jpg,jpeg',url:"{:url('Upload/upload')}",domain:""});
    layui.use(['form','upload','layedit','laydate'], function() {
        var form = layui.form;
        form.on('submit(component-form-element)', function (data) {
            $('.layui-btn').addClass('layui-disabled').attr('disabled','disabled');
            $.ajax({
                url:"{:url('memberedit')}",
                type:'post',
                dataType:'json',
                data:data.field,
                success:function(res){
                    if (res.code == 200) {
                        layer.msg(res.msg,{icon:1,time:1500,shade:0.1},function(index){
                            wk.layer_close();
                        })
                    } else {
                        wk.error(res.msg,'','$(".layui-btn").removeClass(\'layui-disabled\').removeAttr(\'disabled\');');
                    }
                }
            })
        });
        form.on('select(role)', function(data){
            var pid = data.value;
            if(pid == ''){
                $('#l_student').empty();
            }else{
                $.ajax({
                    url:"{:url('admin/Member/getGradeBySchool')}",
                    dataType: 'json',
                    data : 'pid='+pid,
                    type: 'post',
                    success: function (returndata) {
                        if(returndata.code == 200){
                            var data = returndata.msg;
                            $("#l_student").empty();//清空下拉框的值
                            $('#l_student').append(new Option('请选择年级', ' '));// 下拉菜单里添加元素
                            $.each(data, function (index, item) {
                                $('#l_student').append(new Option(item.name, item.id));// 下拉菜单里添加元素
                            });
                            layui.form.render("select");//重新渲染 固定写法
                        }else{
                            alert ('error');
                        }
                    }
                });
            }
        });
    });
</script>
